Skip to content

test(frontend): lint the Playwright waits that depend on time - #542

Merged
pdevito3 merged 5 commits into
mainfrom
correct/playwright-timing-lint
Nov 21, 2026
Merged

pdevito3 merged 5 commits into
mainfrom
correct/playwright-timing-lint

Conversation

@pdevito3

@pdevito3 pdevito3 commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

Why

Agents kept writing Playwright tests that pass or fail by the speed of the machine (#502, #490, #494, #507 and more). eslint already refused waitForTimeout and setTimeout. These forms still got through: a mock with a fixed delay, a goto that waits only for the commit and then gives the app load to a 5 s expect, a wait that starts after the action, and a short timeout option.

What changed

  • MockRoute has no delayMs. A test holds an answer with api.hold and answers it at the step that needs it. tsc refuses a delay.
  • openAndWaitForLogin(page, url) in tests/support/answers.ts opens a URL that goes to the login. It waits for the load and for the answer of the login, which the test timeout limits, not a 5 s expect. A lint refuses waitUntil: 'commit' in tests/, and its message names the helper.
  • A typed rule, playwright/arm-wait-first, refuses an await of a wait (waitForResponse, waitForRequest, waitForEvent, a sync function that gives a Playwright Response or Request, or a Promise.all of only waits), and a wait that the next statement awaits. It runs on tests/ and e2e/.
  • A lint refuses a timeout option in tests/. Its message names the fix: arm a wait, or hold the answer.
  • Every current hit is fixed: 5 delayMs mocks, 3 commit gotos, 2 serial wait loops (now one counting answered(..., nth)), a 2 s expect, and the Swagger popup close in e2e/auth-flows.spec.ts.
  • The writing-tests skill and docs/frontend/testing.md run the changed specs with --repeat-each=10 before a push.

Scope

Frontend tests, their lint config, and docs. No app code, no Server code.

Tradeoffs

Blast Radius

Lint and test code only. A new test with one of these forms fails pnpm lint. api.mock({ ..., delayMs }) no longer compiles.

Verification

Each check fails on real past code: see the proof comment, with SHAs 66b3a8f^, a2fd97e^, and 3b7a3c7. All local (CI has no minutes):

  • pnpm lint, pnpm build: exit 0. pnpm test: 880 passed (79 in eslint.config.test.js).
  • pnpm test:e2e: 370 passed. Changed specs --repeat-each=10: 1090 passed. The login specs with a plain goto, --repeat-each=5: 325 passed.
  • pnpm test:e2e:stack on an isolated stack with ZeroFactor: 9 passed, 5 skipped, Swagger popup included.

… MockRoute

A fixed delay of a mock races the test: on a slow machine the answer comes
before the assertion that needs it in flight, and a short timeout fails
before the work ends. api.hold has no time. The six tests that used
delayMs now hold the answer and release it at the step that needs it, and
the link test of the invite dialog drops its 2 s timeout.
…rLogin, and lint a commit-only navigation

A goto with waitUntil 'commit' leaves the load of the app to the next
expect, whose 5 s were too short on a slow machine (#502). The three
tasks that open a link to the login now call one helper. It waits for
the load and for the answer of the login, which the test timeout
limits. The lint refuses waitUntil 'commit' in each file of tests/, and
its message names the helper.
A wait for an answer or an event starts when it is called, so an await
of waitForResponse, waitForRequest, waitForEvent, or a wrapper such as
answered() after the action misses an answer that came first. The new
typed rule playwright/arm-wait-first reports such an await, and a wait
in a const that the next statement awaits. Its message gives the armed
form.

Three waits on main had this form. The two reconnect tasks of the
invites awaited one answer after the other, so they now give the number
of the answer to one wait. The Swagger popup test of the stack suite
armed its close wait after the login.
A short timeout fails on a slow machine, as the 2 s wait of the invite
link did against a 3 s delay of the list. A long one guesses how slow
the machine is. The lint refuses a timeout option in tests/, and its
message names the armed wait and api.hold. The stack suite keeps its
timeouts, because it waits on real IdPs.
The writing-tests skill named a run of the whole functional suite 10
times, about 25 minutes. It now runs the whole suite once, and then
--only-changed=main 10 times: each spec that differs from main, and
each spec that imports a changed file.
@pdevito3

Copy link
Copy Markdown
Owner Author

Proof: each new check fails on real code

Run in frontend/ at the branch head. lint-past.sh writes the file of a past commit beside the real file (so its imports and the lint config match), lints it, and deletes it.

delayMs removed from MockRoute (TypeScript)

a2fd97e replaced a delayMs: 500 mock with api.hold. Its parent file:

$ git show a2fd97e6^:frontend/tests/features/start-tenant/start-tenant.spec.ts > tests/features/start-tenant/proof-start-tenant.ts && pnpm exec tsc -p tsconfig.tests.json --noEmit
tests/features/start-tenant/proof-start-tenant.ts(161,57): error TS2353: Object literal may only specify known properties, and 'delayMs' does not exist in type 'MockRoute'.

waitUntil: commit, playwright/arm-wait-first, and the timeout option (ESLint)

66b3a8f (#507, closes #502) is the fix of the 5 s login wait. Its parent files, and the files on main 3b7a3c7 that this PR fixes. No merged commit has fixed a late wait or a timeout option yet, so their proof is the code that 66b3a8f^ and main still hold:

$ git show 66b3a8f6^:frontend/tests/features/invites/invites.tasks.ts > tests/features/invites/proof-invites.tasks.ts && pnpm exec eslint tests/features/invites/proof-invites.tasks.ts
tests/features/invites/proof-invites.tasks.ts
  136:9   error  This wait starts after the action before it, so it misses an answer or an event that came first. Arm the wait before the action, and await it after the action: `const answer = answered(...)`, then the action, then `await answer`                                                 playwright/arm-wait-first
  137:9   error  This wait starts after the action before it, so it misses an answer or an event that came first. Arm the wait before the action, and await it after the action: `const answer = answered(...)`, then the action, then `await answer`                                                 playwright/arm-wait-first
  149:48  error  Do not set a timeout. A short one fails on a slow machine, and a long one guesses how slow the machine is. Wait for the event that ends the work: arm a wait for its answer before the action, or hold the answer with api.hold and answer it at the step that needs it              no-restricted-syntax
  223:51  error  A navigation that waits only for the commit leaves the load of the app to the next expect, and its 5 s are too short on a slow machine. To open a URL that goes to the login, call openAndWaitForLogin(page, url) from @tests/support/answers. It waits for the answer of the login  no-restricted-syntax
  249:44  error  This wait starts after the action before it, so it misses an answer or an event that came first. Arm the wait before the action, and await it after the action: `const answer = answered(...)`, then the action, then `await answer`                                                 playwright/arm-wait-first
✖ 5 problems (5 errors, 0 warnings)
exit=1
$ git show 66b3a8f6^:frontend/tests/features/session/session.tasks.ts > tests/features/session/proof-session.tasks.ts && pnpm exec eslint tests/features/session/proof-session.tasks.ts
tests/features/session/proof-session.tasks.ts
  30:31  error  A navigation that waits only for the commit leaves the load of the app to the next expect, and its 5 s are too short on a slow machine. To open a URL that goes to the login, call openAndWaitForLogin(page, url) from @tests/support/answers. It waits for the answer of the login  no-restricted-syntax
  40:31  error  A navigation that waits only for the commit leaves the load of the app to the next expect, and its 5 s are too short on a slow machine. To open a URL that goes to the login, call openAndWaitForLogin(page, url) from @tests/support/answers. It waits for the answer of the login  no-restricted-syntax
✖ 2 problems (2 errors, 0 warnings)
exit=1
$ git show 3b7a3c71:frontend/tests/features/invites/invites.tasks.ts > tests/features/invites/proof-invites.tasks.ts && pnpm exec eslint tests/features/invites/proof-invites.tasks.ts
tests/features/invites/proof-invites.tasks.ts
  134:9   error  This wait starts after the action before it, so it misses an answer or an event that came first. Arm the wait before the action, and await it after the action: `const answer = answered(...)`, then the action, then `await answer`                                                 playwright/arm-wait-first
  135:9   error  This wait starts after the action before it, so it misses an answer or an event that came first. Arm the wait before the action, and await it after the action: `const answer = answered(...)`, then the action, then `await answer`                                                 playwright/arm-wait-first
  147:48  error  Do not set a timeout. A short one fails on a slow machine, and a long one guesses how slow the machine is. Wait for the event that ends the work: arm a wait for its answer before the action, or hold the answer with api.hold and answer it at the step that needs it              no-restricted-syntax
  224:51  error  A navigation that waits only for the commit leaves the load of the app to the next expect, and its 5 s are too short on a slow machine. To open a URL that goes to the login, call openAndWaitForLogin(page, url) from @tests/support/answers. It waits for the answer of the login  no-restricted-syntax
  259:44  error  This wait starts after the action before it, so it misses an answer or an event that came first. Arm the wait before the action, and await it after the action: `const answer = answered(...)`, then the action, then `await answer`                                                 playwright/arm-wait-first
✖ 5 problems (5 errors, 0 warnings)
exit=1
$ git show 3b7a3c71:frontend/e2e/auth-flows.spec.ts > e2e/proof-auth-flows.spec.ts && pnpm exec eslint e2e/proof-auth-flows.spec.ts
e2e/proof-auth-flows.spec.ts
  376:7  error  This wait starts after the action before it, so it misses an answer or an event that came first. Arm the wait before the action, and await it after the action: `const answer = answered(...)`, then the action, then `await answer`  playwright/arm-wait-first
✖ 1 problem (1 error, 0 warnings)
exit=1

@pdevito3

Copy link
Copy Markdown
Owner Author

review-gate: passed 9d819450ec91f673f4eb0fd2c7327c6feac2c295

Reviewer: pdstack:thermo-nuclear-review-subagent (opus). No high or medium findings. The low findings that stay open, with reasons:

  • The rule exempts any async function, so an async wrapper of a wait, or await page.waitForResponse(...).then(...), passes. Kept: the exemption is what lets an async action arm its own wait (followLinkFromAnotherSite), and the doc states it. A tighter check is a follow-up if agents start to use that way out.
  • The rule also reports an await of a wait inside an IIFE that was armed before the action. Kept on purpose: the two such sites now use answered(..., nth), which is simpler.
  • Skill step 6 dropped the full functional run. Fixed after the review in 4eac065: the step runs pnpm test:e2e once, then the changed specs 10 times.
  • The Swagger popup close wait now shares its 30 s with the IdP login. Kept: the stack suite passed on ZeroFactor, and the old form missed a popup that closed during the login.
  • The no-restricted-syntax entries have no unit tests (as the other testFileRules entries), and miss an option object held in a variable. Kept: each is proved on past code in the proof comment, and the inline form is the one agents write.
  • The commit lint message says the load goes to the next expect; on main the next step was the login wait. Kept: the message describes the test(frontend): join.spec INV-3 fails under load, because it waits only 5 seconds for the login redirect #502 form, which 66b3a8f^ shows.

@pdevito3

Copy link
Copy Markdown
Owner Author

PASS+NOTES at head 4eac065

An independent check in a separate detached worktree. All runs are local, because CI has no minutes.

Fault forms written as a developer writes them (scratch files in tests/features/start-tenant/, removed after the check)

Form Check Result
await page.waitForResponse(...) after a click playwright/arm-wait-first error, names the armed-const fix
await answered(...) after a click (sync helper) playwright/arm-wait-first error
await Promise.all([answered(), answered()]) after a click playwright/arm-wait-first error
await page.waitForEvent('popup') after a click playwright/arm-wait-first error
const answer = answered(...) then await answer on the next line (also as const r = await answer) playwright/arm-wait-first error
page.goto(url, { waitUntil: 'commit' }) no-restricted-syntax error, names openAndWaitForLogin
toBeVisible({ timeout: 2000 }), click({ timeout: 1000 }) no-restricted-syntax error, names arm-a-wait or api.hold
api.mock({ ...route, delayMs: 500 }) tsc -p tsconfig.tests.json TS2353, 'delayMs' does not exist in type 'MockRoute'

Correct forms: all pass with no false positive. These are an armed wait awaited after the action (with and without its value), an armed Promise.all, Promise.all([wait, action]), an armed popup, const response = await page.goto('/'), goto with waitUntil: 'load', openAndWaitForLogin, a reload with an armed wait, page.request.get, await r.response() on a request in hand, expect.poll, and api.hold(...) in a spec.

Suite at 4eac065

  • pnpm lint: exit 0. pnpm build: exit 0.
  • pnpm test: 94 files, 880 passed, no type errors.
  • pnpm test:e2e: 370 passed (2.3 min).
  • Changed specs (invites, join, session, weather-forecast) with --repeat-each=5: 545 passed, 0 flaky, 0 failed.
  • Not run: pnpm test:e2e:stack, so the Swagger popup change in e2e/auth-flows.spec.ts was not run again. The author reports 9 passed on ZeroFactor.

Notes (none blocks the merge)

  1. The timeout ban matches any object literal with a timeout key that is passed straight to a call. For example, JSON.stringify({ timeout: 30 }) or a builder for a DTO with a timeout field fails lint. Today no test or app DTO has such a key, so no current code hits this. If a domain field named timeout comes later, limit the selector to Playwright receivers.
  2. Known gaps, confirmed: await answered(...).then(...) and an async wrapper of a wait both pass the rule. Both are in the review-gate comment.
  3. For a stored wait awaited on the next line with no action before it, the message says "starts after the action before it". The fix it names is still right.

@pdevito3
pdevito3 merged commit 3c2817a into main Nov 21, 2026
23 checks passed
@pdevito3
pdevito3 deleted the correct/playwright-timing-lint branch November 21, 2026 04:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant